home *** CD-ROM | disk | FTP | other *** search
- /*
- <!-- ***** BEGIN LICENSE BLOCK *****
- - Version: MPL 1.1/LGPL 2.1
- -
- - The contents of this file are subject to the Mozilla Public License Version
- - 1.1 (the "License"); you may not use this file except in compliance with
- - the License. You may obtain a copy of the License at
- - http://www.mozilla.org/MPL/
- -
- - Software distributed under the License is distributed on an "AS IS" basis,
- - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- - for the specific language governing rights and limitations under the
- - License.
- -
- - The Original Code is PeerAware Workspace User Interface.
- -
- - The Initial Developer of the Original Code is
- - Imunin Software Inc.
- - Portions created by the Initial Developer are Copyright (C) 2006-2008
- - the Initial Developer. All Rights Reserved.
- -
- - Contributor(s):
- -
- - Alternatively, the contents of this file may be used under the terms of
- - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- - in which case the provisions of the LGPL are applicable instead
- - of those above. If you wish to allow use of your version of this file only
- - under the terms of the LGPL, and not to allow others to
- - use your version of this file under the terms of the MPL, indicate your
- - decision by deleting the provisions above and replace them with the notice
- - and other provisions required by the LGPL. If you do not delete
- - the provisions above, a recipient may use your version of this file under
- - the terms of any one of the MPL or the LGPL.
- -
- - ***** END LICENSE BLOCK ***** -->
- */
-
- var xmlHttpRequest;
- var xslt;
- var iPathUp;
- var iUser;
- var iHub;
- var iPath;
- var iCheckedFilesCount = 0;
- var iCheckedImagesCount = 0;
- var qsParm = new Array();
- var iDS;
- function loadPublicList(){XHR(iDS);}
- function SetPublicHublist(aHublist){
- iDS = aHublist;
- window.setTimeout('loadPublicList()', 10);}
-
- function show(object)
- {
- try
- {
- document.all[object].style.visibility='visible';document.all[object].style.display='';
- }
- catch (E)
- {
- }
- }
-
- function hide(object)
- {
- try
- {
- document.all[object].style.visibility='hidden';document.all[object].style.display='none';
- }
- catch (E)
- {
- }
- }
-
- function disableMenu(object)
- {
- try
- {
- document.all[object].className = "barbutton barbutton_Disabled";
- }
- catch (E)
- {
- alert("c " + object)
- }
- }
-
- function enableMenu(object)
- {
- document.all[object].className = "barbutton";
- }
-
-
- function XHR(url)
- {
- try
- {
- xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
- xmlHttpRequest.open("GET", url, true);
- xmlHttpRequest.onreadystatechange = XHRhandler;
- xmlHttpRequest.send(null);
- }
- catch (E)
- {
- document.all("plist").innerHTML = "Could not load " + url;
- }
- }
-
- function XHRhandler()
- {
- if (xmlHttpRequest.readyState == 4)
- {
- if(xmlHttpRequest.status == 200)
- {
- var xsl = new ActiveXObject("Microsoft.XMLDOM");
- xsl.async = false;
- xsl.loadXML(xslt);
- document.all("plist").innerHTML = xmlHttpRequest.responseXML.transformNode(xsl);
- $("tname").innerHTML=getTranslation(1);
- $("tsize").innerHTML=getTranslation(43);
- $("tdate").innerHTML=getTranslation(210);
-
- var pathValue = xmlHttpRequest.responseXML.selectSingleNode("//FileListing");
- var path = pathValue.getAttribute("Base");
- var path_array = path.split("/");
- iPathUp="/";
- for (var loop=0; loop < path_array.length-2; loop++)
- {
- if (path_array[loop].length)
- {
- iPathUp = iPathUp + path_array[loop] + "/";
- }
- }
- //CheckForImages();
- if (path.length<=2)
- {
- hide('ShowUp');
- }
- else
- {
- show('ShowUp');
- }
- }
- else
- {
- document.all("plist").innerHTML = "Could not load " + iDS + "<a href='javascript:window.location.reload();'> retry?</a>";
- }
- }
- }
-
- function decodeutf8(utftext)
- {
- var string = "";
- var i = 0;
- var c = c1 = c2 = 0;
-
- while ( i < utftext.length ) {
-
- c = utftext.charCodeAt(i);
-
- if (c < 128) {
- string += String.fromCharCode(c);
- i++;
- }
- else if((c > 191) && (c < 224)) {
- c2 = utftext.charCodeAt(i+1);
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- }
- else {
- c2 = utftext.charCodeAt(i+1);
- c3 = utftext.charCodeAt(i+2);
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
-
- }
-
- return string;
- }
-
-
- function encodeutf8(string)
- {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
-
- for (var n = 0; n < string.length; n++)
- {
- var c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- }
- return utftext;
- }
-
- function OpenFile(aFile, aSize, aHash)
- {
- window.open('http://localhost:' + qsParm['port'] + '/remoteShare/' + iHub + '/' + encodeURIComponent(qsParm['user']) + iPath + aFile + '?size=' + aSize + '&hash=TTH/' + aHash, "_self");
- }
-
- function BrowseFolder(aFolder)
- {
- window.open('Browse.html?port=' + qsParm['port'] + '&path=' + encodeURIComponent(encodeURIComponent(encodeutf8(iPath + aFolder + '/'))) + '&hub=' + encodeURIComponent(encodeURIComponent(encodeutf8(iHub))) + '&user=' + qsParm['user'], "_self", "", false);
- }
-
- function GoUp()
- {
- window.open('Browse.html?port=' + qsParm['port'] + '&path=' + encodeURIComponent(encodeURIComponent(encodeutf8(iPathUp))) + '&hub=' + encodeURIComponent(encodeURIComponent(encodeutf8(iHub))) + '&user=' + qsParm['user'], "_self");
- }
-
- function CheckFile(fileControl)
- {
- var name = fileControl.name.toLowerCase();
- var found = false;
- if (name.indexOf('.jpg')!=-1 || name.indexOf('.jpeg')!=-1 || name.indexOf('.ico')!=-1 || name.indexOf('.bmp')!=-1 || name.indexOf('.gif')!=-1 || name.indexOf('.png')!=-1 || name.indexOf('.tif')!=-1)
- found=true;
- if (fileControl.checked)
- {
- iCheckedFilesCount++;
- if(iCheckedFilesCount==1)
- {
- enableMenu("DownloadSelected");
- }
- if (found)
- {
- iCheckedImagesCount++;
- if(iCheckedImagesCount==1)
- {
- enableMenu("StartSlideShow");
- }
- }
- }
- else
- {
- iCheckedFilesCount--;
- if(iCheckedFilesCount == 0)
- {
- disableMenu("DownloadSelected");
- }
- if (found)
- {
- iCheckedImagesCount--;
- if(iCheckedImagesCount==0)
- {
- disableMenu("StartSlideShow");
- }
- }
- }
- }
-
- function checkAll()
- {
- var check = false;
- var inputElements = document.all['plist'].getElementsByTagName("input");
- if (inputElements.length)
- {
- if(inputElements[0].checked == true)
- check = true;
- }
- for (i = 1; i < inputElements.length; i++)
- {
- if(inputElements[i].checked != check)
- {
- inputElements[i].checked = check;
- CheckFile(inputElements[i]);
- }
- }
- }
-
- function downloadSelected()
- {
- var check = false;
- var inputElements = document.all['plist'].getElementsByTagName("input");
- for (i = 1; i < inputElements.length; i++)
- {
- if (inputElements[i].controltype == 'file' && (inputElements[i].checked == true || iCheckedFilesCount == 0))
- {
- window.external.DownloadFile(iPath + inputElements[i].name, inputElements[i].fsize, inputElements[i].TTH, iUser, iHub);
- }
- else if (inputElements[i].controltype == 'folder' && (inputElements[i].checked == true || iCheckedFilesCount == 0))
- window.external.DownloadFolder(iPath + inputElements[i].name + "/", iUser, iHub);
- }
- }
-
- function getTranslation(aID)
- {
- if (typeof(window.external)!="undefined" && typeof(window.external.getTranslation)!="undefined")
- return window.external.getTranslation(aID);
- }
-
- function $(aID)
- {
- return document.getElementById(aID)
- }
-
- function setLanguageStrings()
- {
- $("tdownload").innerHTML = getTranslation(93);
- $("tslideshow").innerHTML = getTranslation(201);
- $("StartSlideShow").title=getTranslation(203);
- $("DownloadSelected").title=getTranslation(202);
- $("tprev").title=getTranslation(209);
- $("playbutton").title=getTranslation(205);
- $("tstop").title=getTranslation(207);
- $("pausebutton").title=getTranslation(206);
- $("tnext").title=getTranslation(208);
- }
-
- function browsePage()
- {
- setLanguageStrings();
- hide("slideshow");
- disableMenu("StartSlideShow");
- disableMenu("DownloadSelected");
- var query = decodeURIComponent(window.location.search.substring(1));
- var parms = query.split('&');
- for (var i=0; i<parms.length; i++)
- {
- var pos = parms[i].indexOf('=');
- if (pos > 0)
- {
- var key = parms[i].substring(0,pos);
- var val = parms[i].substring(pos+1);
- qsParm[key] = val;
- }
- }
-
- iHub = decodeURIComponent(qsParm['hub']);
-
- //user is not always utf-8 encoded:
- try
- {
- iUser = decodeURIComponent(qsParm['user']);
- }
- catch (E)
- {
- iUser = qsParm['user'];
- }
-
- iPath = decodeURIComponent(qsParm['path']);
-
- document.all("path").innerHTML = decodeutf8(iPath);
- document.all("workspace").innerHTML = iHub;
- document.all("username").innerHTML = iUser;
-
- SetPublicHublist('http://localhost:' + qsParm['port'] + '/remoteShare/' + qsParm['hub'] + '/' + qsParm['user'] + iPath);
-
- show('plist');
- xslt = '<?xml version="1.0" encoding="utf-16"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'
- +'<xsl:template match="/">'
- +'<table class="FileGrid" id="files"><tr class="FileGridHead"><th class="FileGridCellHead" style="width: 25px;" ><input controltype="header" type="checkbox" title="Check all files" onClick="checkAll();"/></th><th class="FileGridHeadCellDef" style="width: 35px;" ><img src="file.gif"/></th><th id="tname" class="FileGridHeadCellDef">Name</th><th class="FileGridHeadCellDef" id="tsize" style="width: 100px;">Size</th><th id="tdate" class="FileGridHeadCellDef" style="width: 180px;">Date Modified</th></tr>'
- +'<tr id="ShowUp"><td/><td class="FileGridCellDefault" align="center"><img src="folder.gif" /></td><td class="FileGridCellDefault" ><a href="javascript:GoUp();" title="Parent Folder">..</a></td></tr>'
- +'<xsl:for-each select="FileListing/Directory"><tr id="folder" class="RowDefault">'
- +'<td align="center"><input type="checkbox" onClick="CheckFile(this);" controltype="folder">'
- +'<xsl:attribute name="name"><xsl:value-of select="@Name" /></xsl:attribute>'
- +' </input></td><td class="FileGridCellDefault" align="center"><img src="folder.gif"/></td><td class="FileGridCellDefault"><a><xsl:attribute name="href">'
- +'javascript:BrowseFolder("<xsl:value-of select="@Name" />");</xsl:attribute><xsl:value-of select="@Name" /></a>'
- +'</td></tr></xsl:for-each>'
- +'<xsl:for-each select="FileListing/File"><tr id="file" class="RowDefault">'
- +'<td align="center"><input type="checkbox" onClick="CheckFile(this);" controltype="file">'
- +'<xsl:attribute name="name"><xsl:value-of select="@Name" /></xsl:attribute><xsl:attribute name="fsize"><xsl:value-of select="@Size" /></xsl:attribute><xsl:attribute name="TTH"><xsl:value-of select="@TTH" /></xsl:attribute>'
- +' </input></td><td class="FileGridCellDefault" align="center"><img src="file.gif"/></td><td class="FileGridCellDefault" ><a><xsl:attribute name="href">javascript:OpenFile("<xsl:value-of select="@Name" />","<xsl:value-of select="@Size" />","<xsl:value-of select="@TTH" />");</xsl:attribute><xsl:value-of select="@Name" /></a></td><td class="FileGridCellDefault" align="right">'
- +'<xsl:choose>'
- +'<xsl:when test="@Size < 1024"><xsl:value-of select="format-number'
- +"(@Size, '#,##0')"
- +'"/> Bytes</xsl:when>'
- +'<xsl:when test="@Size < 1048576"><xsl:value-of select="format-number(@Size div 1024, '
- +"'#,###.##')"
- +'"/> KB</xsl:when>'
- +'<xsl:when test="@Size < 1073741824"><xsl:value-of select="format-number(@Size div 1048576, '
- +"'#,###.##')"
- +'"/> MB</xsl:when>'
- +'<xsl:when test="@Size"><xsl:value-of select="format-number(@Size div 1073741824,'
- +" '#,###.##')"
- +'"/> GB</xsl:when>'
- +'</xsl:choose>'
- +'</td><td class="FileGridCellDefault" align="right"><xsl:value-of select="@Date" /></td></tr></xsl:for-each>'
- +'</table>'
- +'</xsl:template>'
- +'</xsl:stylesheet>';
- }
-
- var currentImage = 0;
- var loadingStarted=false;
- var loadingFinished=false;
- var slideshowSelected = false;
- var prefetchImage;
- var timeoutFunction;
- var direction = 'f';
- var playMode = 'run';
- var slideshowsrc;
-
- function XHR3handler()
- {
- document.images.SlideShow.src = slideshowsrc;
- var maxHeight = document.documentElement.clientHeight - 130;
- var maxWidth = document.documentElement.clientWidth - 20;
- var imgWidth = prefetchImage.width;
- var imgHeight = prefetchImage.height;
-
- if(imgHeight > maxHeight)
- {
- imgWidth=(maxHeight/imgHeight)*imgWidth;
- imgHeight=maxHeight;
- }
- if(imgWidth > maxWidth)
- {
- imgHeight=imgHeight*(maxWidth/imgWidth);
- imgWidth=maxWidth;
- }
- document.images.SlideShow.height=imgHeight;
- document.images.SlideShow.width=imgWidth;
- resize();
- document.images.SlideShow.filters.blendTrans.Play();
- loadingFinished=true;
- }
-
-
- function resize()
- {
- var c = document.getElementById('Control');
- c.style.left = document.documentElement.clientWidth/2 - c.clientWidth/2;
- c.style.position='absolute';
- c.style.bottom = '0px';
- }
-
- function setImageText(text)
- {
- document.all("path").innerHTML = iPath + text;
- }
-
- function runSlideShow()
- {
- if (loadingStarted == true && loadingFinished == false)
- {
- timeoutFunction = setTimeout('runSlideShow()', 5000)
- return;
- }
-
- if (document.all)
- {
- document.images.SlideShow.style.filter="blendTrans(duration=0)";
- document.images.SlideShow.filters.blendTrans.Apply();
- }
-
- var inputElements = document.all['plist'].getElementsByTagName("input");
- var i;
- var src='';
-
- if (direction == 'f')
- {
- currentImage = currentImage + 1;
- for (i = currentImage; i < inputElements.length; i++)
- if (inputElements[i].type == 'checkbox' && inputElements[i].controltype=='file' && (slideshowSelected==false || (slideshowSelected && inputElements[i].checked == true)) && inputElements[i].controltype != 'header')
- {
- setImageText(inputElements[i].name);
- src = 'http://localhost:' + qsParm['port'] + '/remoteShare/' + encodeURIComponent(encodeURIComponent(iHub)) + '/' + encodeURIComponent(qsParm['user']) + iPath + inputElements[i].name + '?size=' + inputElements[i].fsize + '&hash=TTH/' + inputElements[i].TTH;
- currentImage = i;
- break;
- }
- }
- else
- {
- currentImage = currentImage - 1;
- for (i = currentImage; i >=0; i--)
- if (inputElements[i].type == 'checkbox' && inputElements[i].controltype=='file' && (slideshowSelected==false || (slideshowSelected && inputElements[i].checked == true)) && inputElements[i].controltype != 'header')
- {
- setImageText(inputElements[i].name);
- src = 'http://localhost:' + qsParm['port'] + '/remoteShare/' + encodeURIComponent(encodeURIComponent(iHub)) + '/' + encodeURIComponent(qsParm['user']) + iPath + inputElements[i].name + '?size=' + inputElements[i].fsize + '&hash=TTH/' + inputElements[i].TTH;
- currentImage = i;
- break;
- }
-
- }
-
- if (currentImage >= inputElements.length && direction == 'f')
- {
- currentImage = 0;
- }
- else if (currentImage == 0 && direction == 'r')
- {
- currentImage = inputElements.length;
- }
-
- if (src!='')
- {
- if (playMode == 'run')
- {
- timeoutFunction = setTimeout('runSlideShow()', 5000)
- }
- loadingStarted = true;
- loadingFinished = false;
- slideshowsrc = src;
- prefetchImage = new Image()
- prefetchImage.onload = XHR3handler;
- //prefetchImage.onabort=XHR3handler;
- //prefetchImage.onerror=XHR3handler;
- prefetchImage.src=src;
- }
- else
- {
- loadingStarted = false;
- loadingFinished = true;
- timeoutFunction = setTimeout('runSlideShow()', 10);
- }
- }
-
- function CheckForImages()
- {
- /*
- var inputElements = document.all['plist'].getElementsByTagName("input");
- for (i = 1; i < inputElements.length; i++)
- if (inputElements[i].controltype == 'file' )
- {
- name = inputElements[i].name.toLowerCase();
- if (name.indexOf('.jpg')!=-1 || name.indexOf('.jpeg')!=-1 || name.indexOf('.ico')!=-1 || name.indexOf('.bmp')!=-1 || name.indexOf('.gif')!=-1 || name.indexOf('.png')!=-1 || name.indexOf('.tif')!=-1)
- {
- //show("StartSlideShowAll");
- break;
- }
- }
- */
- }
-
- function previous()
- {
- direction = 'r';
- clearTimeout(timeoutFunction);
- loadingStarted = false;
- runSlideShow();
- }
-
- function play()
- {
- hide("playbutton");
- show("pausebutton");
- playMode = 'run';
- direction = 'f';
- clearTimeout(timeoutFunction);
- loadingStarted = false;
- runSlideShow();
- }
-
- function pause()
- {
- playMode = 'step';
- clearTimeout(timeoutFunction);
- loadingStarted = false;
- show("playbutton");
- hide("pausebutton");
- }
-
- function stop()
- {
- playMode = 'step';
- clearTimeout(timeoutFunction);
- loadingStarted = false;
- currentImage = 0;
- show('plist');
- show('toolbar');
- hide('slideshow');
- loadingStarted = false;
- slideshowSelected = false;
- document.all("path").innerHTML = iPath;
- }
-
- function next()
- {
- direction = 'f';
- clearTimeout(timeoutFunction);
- loadingStarted = false;
- runSlideShow();
- }
-
- function StartSlideShow()
- {
- if (iCheckedImagesCount)
- {
- slideshowSelected = iCheckedImagesCount>0;
- hide('plist');
- hide('toolbar');
- show('slideshow');
- resize();
- play();
- }
- }
-